package com.controller;

import com.entity.Response;
import com.entity.pojo.WrTeam;
import com.service.TeamUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("TeamUser")
public class TeamUserController {

    @Resource
    private TeamUserService teamUserService;

    @PostMapping
    private Response addUserToTeam(@RequestParam("Userid") Integer userId,
                                   @RequestParam("teamId") Integer teamId) {
        int res = teamUserService.addUserToTeam(userId, teamId);
        return res > 0 ? new Response().setSuccess() : new Response().setFailed();
    }

    @PutMapping("/cleanTeam")
    private Response cleanUserTeam(@RequestBody WrTeam wrTeam) {
        int res = teamUserService.cleanUserTeam(wrTeam.getId());
        return res > 0 ? new Response().setSuccess() : new Response().setFailed();
    }

    @DeleteMapping
    private Response deleteUserTeam(@RequestParam("Userid") Integer userId,
                                    @RequestParam("teamId") Integer teamId) {
        int res = teamUserService.removeUserFromTeam(userId, teamId);
        return res > 0 ? new Response().setSuccess() : new Response().setFailed();
    }
}
